<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta content="webkit" name="renderer">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
    <style>img {
        width: 100%;
        height: auto;
    }</style>
    <link href="../css/xadmin.css" rel="stylesheet">
    <link href="../lib/layui/css/layui.css" rel="stylesheet" type="text/css">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body class="form-wrap">
    <div class="layui-fluid">

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>常规轮播</legend>
        </fieldset>

        <div class="layui-carousel" id="test1" lay-filter="test1">
            <div carousel-item="">
                <div class="layui-bg-gray">条目1</div>
                <div class="layui-bg-green">条目2</div>
                <div class="layui-bg-gray">条目3</div>
                <div class="layui-bg-gray">条目4</div>
            </div>
        </div>

        <div class="layui-carousel" id="test2" style="margin-top: 15px;">
            <div carousel-item="">
                <div class="layui-bg-gray">条目1</div>
                <div class="layui-bg-gray">条目2</div>
            </div>
        </div>

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>设定各种参数</legend>
        </fieldset>
        <div class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">宽高</label>
                    <div class="layui-input-inline" style="width: 98px;">
                        <input autocomplete="off" class="layui-input demoSet" name="width" placeholder="width"
                               type="tel"
                               value="600">
                    </div>
                    <div class="layui-input-inline" style="width: 98px;">
                        <input autocomplete="off" class="layui-input demoSet" name="height" placeholder="height"
                               type="tel"
                               value="280">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">动画类型</label>
                <div class="layui-input-block">
                    <div class="layui-btn-group demoTest" style="margin-top: 5px;">
                        <button class="layui-btn layui-btn-sm" data-key="anim" data-type="set"
                                data-value="default" style="background-color: #5FB878;">左右切换
                        </button>
                        <button class="layui-btn layui-btn-sm" data-key="anim" data-type="set" data-value="updown">上下切换
                        </button>
                        <button class="layui-btn layui-btn-sm" data-key="anim" data-type="set" data-value="fade">渐隐渐显
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">箭头状态</label>
                <div class="layui-input-block">
                    <div class="layui-btn-group demoTest" style="margin-top: 5px;">
                        <button class="layui-btn layui-btn-sm" data-key="arrow" data-type="set"
                                data-value="hover" style="background-color: #5FB878;">悬停显示
                        </button>
                        <button class="layui-btn layui-btn-sm" data-key="arrow" data-type="set" data-value="always">始终显示
                        </button>
                        <button class="layui-btn layui-btn-sm" data-key="arrow" data-type="set" data-value="none">不显示
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">指示器位置</label>
                <div class="layui-input-block">
                    <div class="layui-btn-group demoTest" style="margin-top: 5px;">
                        <button class="layui-btn layui-btn-sm" data-key="indicator" data-type="set"
                                data-value="inside" style="background-color: #5FB878;">容器内部
                        </button>
                        <button class="layui-btn layui-btn-sm" data-key="indicator" data-type="set"
                                data-value="outside">
                            容器外部
                        </button>
                        <button class="layui-btn layui-btn-sm" data-key="indicator" data-type="set" data-value="none">
                            不显示
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">自动切换</label>
                    <div class="layui-input-block">
                        <input checked="" lay-filter="autoplay" lay-skin="switch" lay-text="ON|OFF" name="switch"
                               type="checkbox">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: auto;">时间间隔</label>
                    <div class="layui-input-inline" style="width: 120px;">
                        <input autocomplete="off" class="layui-input demoSet" name="interval" placeholder="毫秒"
                               type="tel"
                               value="3000">
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-carousel" id="test3" lay-filter="test4">
            <div carousel-item="">
                <div class="layui-bg-gray">条目1</div>
                <div class="layui-bg-gray">条目2</div>
                <div class="layui-bg-gray">条目3</div>
                <div class="layui-bg-gray">条目4</div>
                <div class="layui-bg-gray">条目5</div>
            </div>
        </div>

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
            <legend>填充轮播元素 - 以图片为例</legend>
        </fieldset>

        <div class="layui-carousel" id="test10">
            <div carousel-item="">
                <div><img src="../images/pic/1.png"></div>
                <div><img src="../images/pic/2.png"></div>
                <div><img src="../images/pic/3.png"></div>
            </div>
        </div>


        <script charset="utf-8" src="../lib/layui/layui.js" type="text/javascript"></script>
        <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
        <script>
            layui.use(['carousel', 'form'], function () {
                var carousel = layui.carousel
                    , form = layui.form;

                //常规轮播
                carousel.render({
                    elem: '#test1'
                    , arrow: 'always'
                });

                //改变下时间间隔、动画类型、高度
                carousel.render({
                    elem: '#test2'
                    , interval: 1800
                    , anim: 'fade'
                    , height: '120px'
                });

                //设定各种参数
                var ins3 = carousel.render({
                    elem: '#test3'
                });
                //图片轮播
                carousel.render({
                    elem: '#test10'
                    , width: '800px'
                    , height: '440px'
                    , interval: 5000
                });

                //事件
                carousel.on('change(test4)', function (res) {
                    console.log(res)
                });

                var $ = layui.$, active = {
                    set: function (othis) {
                        var THIS = 'layui-bg-normal'
                            , key = othis.data('key')
                            , options = {};

                        othis.css('background-color', '#5FB878').siblings().removeAttr('style');
                        options[key] = othis.data('value');
                        ins3.reload(options);
                    }
                };

                //监听开关
                form.on('switch(autoplay)', function () {
                    ins3.reload({
                        autoplay: this.checked
                    });
                });

                $('.demoSet').on('keyup', function () {
                    var value = this.value
                        , options = {};
                    if (!/^\d+$/.test(value)) return;

                    options[this.name] = value;
                    ins3.reload(options);
                });

                //其它示例
                $('.demoTest .layui-btn').on('click', function () {
                    var othis = $(this), type = othis.data('type');
                    active[type] ? active[type].call(this, othis) : '';
                });
            });
        </script>


    </div>
</body>
</html>